<template>
    <el-dialog :title="form.id ? '编辑' : '新增'" :visible.sync="visible" :close-on-click-modal="false">
        <el-form ref="form" :model="form" :rules="rules">
            <el-form-item label="分组名称" :label-width="formLabelWidth" prop="name">
                <el-input
                        v-model="form.name"
                        autocomplete="off"
                        placeholder="请输入分组名称"
                ></el-input>
            </el-form-item>
            <el-form-item label="描述" :label-width="formLabelWidth" prop="describe">
                <el-input
                        v-model="form.describe"
                        autocomplete="off"
                        placeholder="请输入描述"
                ></el-input>
            </el-form-item>
            <el-form-item label="创建人" :label-width="formLabelWidth" prop="createUser">
                <el-input
                        v-model="form.createUser"
                        autocomplete="off"
                        placeholder="请输入创建人"
                ></el-input>
            </el-form-item>
            <el-form-item label="创建时间" :label-width="formLabelWidth" prop="createTime">
                <el-input
                        v-model="form.createTime"
                        autocomplete="off"
                        placeholder="请输入创建时间"
                ></el-input>
            </el-form-item>
            <el-form-item label="修改人" :label-width="formLabelWidth" prop="updateUser">
                <el-input
                        v-model="form.updateUser"
                        autocomplete="off"
                        placeholder="请输入修改人"
                ></el-input>
            </el-form-item>
            <el-form-item label="修改时间" :label-width="formLabelWidth" prop="updateTime">
                <el-input
                        v-model="form.updateTime"
                        autocomplete="off"
                        placeholder="请输入修改时间"
                ></el-input>
            </el-form-item>
            <el-form-item label="是否删除YesNoEnum" :label-width="formLabelWidth" prop="isDeleted">
                <el-input
                        v-model="form.isDeleted"
                        autocomplete="off"
                        placeholder="请输入是否删除YesNoEnum"
                ></el-input>
            </el-form-item>
            <el-form-item label="状态" :label-width="formLabelWidth" prop="status">
                <el-input
                        v-model="form.status"
                        autocomplete="off"
                        placeholder="请输入状态"
                ></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" >
            <el-button @click="visible = false" size="medium" type="danger">取 消</el-button>
            <el-button type="primary" size="medium" @click="submitForm('form')">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
    import { membergroupInfo, membergroupSave, membergroupEdit } from "@/api/member/grop/membergroup.js";
    
    
    export default {
        data() {
            return {
                visible: false,
                form: {
                    id:"",
                    name:"",
                    describe:"",
                    createUser:"",
                    createTime:"",
                    updateUser:"",
                    updateTime:"",
                    isDeleted:"",
                    status:"",
                },
                formLabelWidth: "120px",
                rules: {
                },
            };
        },
        created() {
        },
        methods: {
            init(id) {
                this.resetForm();
                //修改
                if (id) {
                    membergroupInfo(id).then((resp) => {
                        if (resp.code == 0) {
                            this.$nextTick(() => {
                                this.form = {
                                    ...this.form,
                                    ...resp.data,
                                };
                            });
                        } else {
                            this.$msg({
                                message: resp.msg,
                                type: "error",
                            });
                        }
                    });
                }
                this.visible = true;
            },
            //提交表单数据
            submitForm() {
                this.$refs["form"].validate((valid) => {
                if (valid) {
                    //修改
                    if (this.form.id) {
                        membergroupEdit(this.form).then((resp) => {
                            if (resp.code == 0) {
                                this.$message({
                                    type: "success",
                                    message: "操作成功!",
                                });
                            this.$emit("refreshData");
                            this.visible = false;
                            } else {
                                this.$msg({
                                    message: resp.msg,
                                    type: "error",
                                });
                            }
                        });
                    //新增
                    } else {
                        membergroupSave(this.form).then((resp) => {
                            if (resp.code == 0) {
                                this.$message({
                                    type: "success",
                                    message: "操作成功!",
                                });
                                this.$emit("refreshData");
                                this.visible = false;
                            } else {
                                this.$msg({
                                    message: resp.msg,
                                    type: "error",
                                });
                            }
                        });
                    }
                } else {
                    console.log("error submit!!");
                    return false;
                }
                });
            },
            resetForm() {
                this.form = {
                    id:"",
                    name:"",
                    describe:"",
                    createUser:"",
                    createTime:"",
                    updateUser:"",
                    updateTime:"",
                    isDeleted:"",
                    status:"",
                };
                this.$nextTick(() => {
                    if (this.$refs["form"]) {
                        this.$refs["form"].resetFields();
                    }
                });
            },
        },
    };
</script>
<style scoped>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409eff;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    .el-scrollbar .el-scrollbar__view .el-select-dropdown__item {
        height: auto;
        max-height: 274px;
        padding: 7px;
        overflow: hidden;
        overflow-y: auto;
        font-weight: normal;
    }
</style>